package com.cooper.scraper;

import java.io.IOException;
import java.net.ConnectException;
import java.net.SocketTimeoutException;

import org.apache.http.client.ClientProtocolException;

import android.util.Log;

public class DownloadException extends Exception{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 6834028343741641789L;
	
	public static final int ERROR_IO = 101;
	public static final int ERROR_CLIENT = 102;
	public static final int ERROR_CONNECT_TIMEOUT = 103;
	public static final int ERROR_SOCKET_TIMEOUT = 104;
	public static final int ERROR_OTHER = 105;

	public DownloadException(String url){
		super();
		Log.e("DownloadException", url ,e);
	}
	
	private Exception e;
	
	public DownloadException(Exception e){
		super(e.getMessage());
		this.e = e;
		Log.e("DownloadException", e.getMessage(),e);
	}
	
	public int getErrorCode(){
		if (e instanceof SocketTimeoutException){
			return ERROR_SOCKET_TIMEOUT;
		}else if (e instanceof ConnectException){
			return ERROR_CONNECT_TIMEOUT;
		}else if (e instanceof ClientProtocolException){
			return ERROR_CLIENT;
		}else if (e instanceof IOException){
			return ERROR_IO;
		}else 
			return ERROR_OTHER;
	}
	
	

}
